package com.pz.cloud.framework.pzStudent.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pz.cloud.framework.base.dao.CommonDao;
import com.pz.cloud.framework.base.model.Pageable;
import com.pz.cloud.framework.business.pzStudent.entity.PzStudentGpa;
import com.pz.cloud.framework.business.pzStudent.service.IPzStudentGpaService;
import com.pz.cloud.framework.model.AbstractSqlBuilder;
import com.pz.cloud.framework.model.SqlBuilder;
import com.pz.cloud.framework.pzStudent.mapper.PzStudentGpaMapper;
import org.jeecg.common.util.dynamic.db.SqlUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@DS("pz")
@Service
@Transactional
public class PzStudentGpaServiceImpl extends ServiceImpl<PzStudentGpaMapper, PzStudentGpa> implements IPzStudentGpaService {

    @Autowired
    private CommonDao commonDao;

    @Override
    public List<PzStudentGpa> findPage(PzStudentGpa entity, Pageable pageable) {
        AbstractSqlBuilder sqlBuilder = SqlBuilder.init("select * from ").appendTable(PzStudentGpa.class).append(" t ");
        return commonDao.findList(SqlBuilder.init(SqlUtils.createPageSqlByDBType("oracle", sqlBuilder.getSql(), pageable.getPageNo(), pageable.getPageSize())).returnType(PzStudentGpa.class));
    }

    @Override
    public List<PzStudentGpa> findList(PzStudentGpa entity) {
        AbstractSqlBuilder sqlBuilder = SqlBuilder.init(entity, "g").returnType(PzStudentGpa.class);
        return commonDao.findList(sqlBuilder);
    }

    @Override
    public PzStudentGpa findByStdNoAndPeriod(String stdNo, String period) {
        AbstractSqlBuilder sqlBuilder = SqlBuilder.init("select * from ").appendTable(PzStudentGpa.class).append(" t ")
                .append(" where XH = :stdNo").setParms("stdNo", stdNo)
                .append(" and XN = :period").setParms("period", period)
                .returnType(PzStudentGpa.class);
        return commonDao.findOne(sqlBuilder);
    }

    @Override
    public List<PzStudentGpa> findByStdNo(String stdNo) {
        AbstractSqlBuilder sqlBuilder = SqlBuilder.init("select * from ").appendTable(PzStudentGpa.class).append(" t ")
                .append(" where XH = :stdNo").setParms("stdNo", stdNo)
                .returnType(PzStudentGpa.class);
        return commonDao.findList(sqlBuilder);
    }
}
